<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>仓库管理</el-breadcrumb-item>
      <el-breadcrumb-item>仓库盘点</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!--        查询框-->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入货物内容"
                    clearable
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table v-loading="loading"
                :data="outList"
                border
                height="490"
                :default-sort="{prop: 'count', order: 'ascending'}"

                :row-class-name="tableRowClassName"
      >
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="RFID编号" prop="num" width="170px" sortable></el-table-column>
        <el-table-column label="订单号" prop="orderNum" width="170px" sortable></el-table-column>
        <el-table-column label="货物名称" prop="name" sortable></el-table-column>
        <el-table-column label="存储数量" prop="count" sortable></el-table-column>
      <!--  <el-table-column label="客户名" prop="client.name"></el-table-column>
        <el-table-column label="联系方式" prop="client.phone"></el-table-column>-->
        <el-table-column label="入库时间" prop="date" width="150px" sortable></el-table-column>
      </el-table>
    </el-card>

  </div>
</template>

<script>
export default {
  data() {
    return {
      outList: [],
      loading: false,
      shipDialog: false,
      enterDialog:false,
      queryInfo: {
        name: '',
        state: 2
      },
      queryInfo1: {
        name: '',
        state: 2
      },
      enter: {
        tNote: '',
        tid: '',
        orderNum: '',
        name: '',
        type: '',
        count: '',
        countQ: 0,
        countD: 0,
        pid: [],
        area1: '',
        area2: 0,
        lid: '',
        operator: this.$store.state.user.name
      },
      ship: {
        id: '',
        area1:'',
        expCode: '',
        expNo: '',

      },
      warehouseId: [],
      position: [],
      query: {
        id: '',
      },
      locationDialog:false,
      locations:[],
      logisticsDialog: false,
      reverse: true,
      kd: {}
    }
  },
  methods: {
    formatter(row, column) {
      return row.address;
    },
    tableRowClassName({row, rowIndex}) {
        if (row.count  <= 50) {
          console.log(row.count)
          return 'warning-row';
        }
        else if (row.count <= 100) {
          return 'jinggao-row';
        }
        else if (row.count <= 200)
        {
          return 'success-row';
        }
        return '';
    },
    //获取仓库盘点
    async getOutList() {
      this.loading = true;
      const res = await this.$http.get('/goods/checkList');
      for (let i = 0; i < res.obj.length; i++) {
        if (res.obj[i].orderNum === '') {
          res.obj[i].orderNum = '自主生产';
        }
      }
      if (res) {
        this.outList = res.obj;
        //console.log(res.obj);
      }
      this.loading = false;
    },
    enterClose() {
      this.enter = {
        tNote: '',
        tid: '',
        tid1:'',
        orderNum: '',
        name: '',
        type: '',
        count: '',
        countQ: 0,
        countD: 0,
        pid: [],
        area1: '',
        area2: '',
        lid: '',
      };
      this.query.id = '';
      this.warehouseId = '';
    },
    openEnter() {
      this.enterDialog = true;
      // this.shipDialog = true;
    },
    async openShip(item) {
      if (item.expNo === null) {
        this.shipDialog = true;
        this.ship.id = item.id;
      } else {
        this.logisticsDialog = true;
        const res = await this.$http.post('/goods/ship', {
          expCode: item.expCode,
          expNo: item.expNo,
        });
        this.kd = JSON.parse(res.obj);
      }

    },
    enterYes() {
      const pid = this.enter.pid;
      const lid = [];
      for (let i = 0; i < pid.length; i++) {
        lid[i] = pid[i][pid[i].length - 1];
      }
      this.enter.lid = lid.join(',');
      console.log(this.enter);
      this.$refs.enterRef.validate(async valid => {
        const res = await this.$http.post('/warehouse/enter', this.enter);
        if (res) {
          this.getEnterList();
          this.enterDialog = false;
        } else return;

        // }

      })

    },

    //远程查询RFID编号
    async querySearchAsync1(queryString, cb) {
      this.queryInfo1.name = queryString;
      const res = await this.$http.get('/warehouse/RFIDProduct/', {params: this.queryInfo1});
      for (let i of res.obj) {
        i.value = i.num+':'+i.name + '(数量:' + i.count + '单号' + i.orderNum + ')';
        // i.value = i.data;
      }
      cb(res.obj);
    },
    handleSelect1(item) {
      this.enter.tid = item.id;
      this.ship.id = item.id;
      this.enter.area1= item.num;
      if (item.orderNum === '') {
        this.enter.orderNum = '自主生产';
      } else {
        this.enter.orderNum = item.orderNum;
      }
      this.enter.name = item.name;
      this.enter.count = item.count;
    },

    async getPosition() {
      console.log(this.query.id);
      const res = await this.$http.get('/warehouse/position/', {params: this.query});
      this.position = res.obj;
      console.log(res);
    },
    async shipYes() {
      const res = await this.$http.put('/goods/out', this.ship);
      if (res) {
        this.shipDialog = false;
        this.getOutList();
      }
    },
    async shipYes1() {
      // console.log(this.ship);
      // console.log("666666");
      // console.log(this.enter);
      // this.ship.expCode;
      const res = await this.$http.put('/goods/out', this.ship);
      if (res) {
        this.shipDialog = false;
        this.getOutList();
      }
    }
  },
  created() {
    this.enterDialog = true;
    this.getOutList();
  }
}
</script>

<!--<style scoped>-->
<style>
  .el-table .warning-row {
    background: #ff6633;
  }

  .el-table .jinggao-row {
    background: #FF9900;
  }
  .el-table .success-row {
    background: #FFFF00;
  }

</style>
